package com.dhl.rabbitmq.seven;

import com.dhl.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.nio.charset.StandardCharsets;

/**
 * @author danghailiang
 */
public class ReceiveLogsTopic01 {
    public static final String EXCHANGE_NAME = "topic_log";

    public static void main(String[] args) throws Exception {
        // 获取信道
        Channel channel = RabbitUtils.getChannel();
        // 获取交换
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        // 获取队列
        String queueName = "Q1";
        channel.queueDeclare(queueName, false, false, false, null);
        // 交换和队列绑定
        channel.queueBind(queueName, EXCHANGE_NAME, "*.orange.*");
        System.out.println(queueName + "topic_log####（*.orange.*）::::获取消息");
        // 成功回调处理
        DeliverCallback deliverCallback = (sepTag, message) -> {
            System.out.println(new String(message.getBody(), StandardCharsets.UTF_8));
        };
        // 失败回调处理
        CancelCallback cancelCallback = (sepTag) -> {
        };
        // 获取消息
        channel.basicConsume(queueName, false, deliverCallback, cancelCallback);
    }

}
